<?php
include("../includes/DBFunctions.php");

function addEventToRegionFunctor( $env, $rid, $dur ) {
	$db = new DBFunctions;
	$db->connectDB();
	$result = $db->query("call addEventToRegion(".$env.",".$rid.",".$dur.",@a)" );
	$errors = $db->query("SELECT @a");
	while( $line = mysqli_fetch_array( $errors, MYSQL_ASSOC ) ) {
		$error = $line['@a'];
	}
	if( !$result || $error != 0 ) {
		die("alert('Failed stored procedure call (addEventToRegion ErrorCode:".$error.")');");
	}
}

if( !isset($_POST['selectEnvironment']) || $_POST['selectEnvironment'] == '') {
	die( "Select Environment was not set.");
}
$env = $_POST['selectEnvironment'];
if( !isset($_POST['selectRegion']) || $_POST['selectRegion'] == '') {
	die( "Select region was not set.");
}
$rid = $_POST['selectRegion'];
if( !isset($_POST['duration']) || $_POST['duration'] == '') {
	die( "Select region was not set.");
}
$dur = $_POST['duration'];

addEventToRegionFunctor($env, $rid, $dur);
?>